using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using bookMaster.AssetSystem.Data;

namespace bookMaster.AssetSystem.Shell.Controles
{
    public partial class ctlFiltroValores : UserControl, IFiltros
    {
        public ctlFiltroValores()
        {
            InitializeComponent();
        }

        private void ctlFiltroValores_Load(object sender, EventArgs e)
        {
            cmbOperador.SelectedIndex = 0;
        }

        public string ValueMember
        {
            set
            {
                cmbValores.ValueMember = value;
            }
        }

        public string DisplayMember
        {
            set
            {
                cmbValores.DisplayMember = value;
            }
        }

        public object Valores
        {
            set
            {
                cmbValores.DataSource = value;

                if (cmbValores.Items.Count > 0)
                {
                    cmbOperador.SelectedIndex = 0;
                }
            }
        }

        public string ValorSeleccionado
        {
            get
            {
                return cmbValores.SelectedValue.ToString();
            }
        }

        public StringBuilderExpression Operador
        {
            get
            {

                if (cmbOperador.Text.ToLower() == "es igual a")
                    return StringBuilderExpression.AppendEquals;

                if (cmbOperador.Text.ToLower() == "es distinto de")
                    return StringBuilderExpression.AppendNotEquals;

                if (cmbOperador.Text.ToLower() == "comienza con")
                    return StringBuilderExpression.AppendStartsWith;

                if (cmbOperador.Text.ToLower() == "termina con")
                    return StringBuilderExpression.AppendEndsWith;

                if (cmbOperador.Text.ToLower() == "contiene")
                    return StringBuilderExpression.AppendContains;

                return StringBuilderExpression.Append;

            }
        }

        public string Valor
        {
            get
            {
                return ValorSeleccionado;
            }
        }

        public bool SetVisible
        {
            set
            {
                this.Visible = value;
            }
        }

    }
}
